
function battleignition(agang, RT, reverse, dudeisent, gangisent, showdamage)
{
	gang = agang;
	gang.dudeisent = (dudeisent) ? dudeisent : [];
	gang.gangisent = (gangisent) ? gangisent : [];
	gang.showdamage = showdamage;
	gang.paused = false;
	gang.fighting = true;
	if (!RT) gang.backdrop = LoadImage("battlebg02.png");
	gang.timebar = LoadImage("timebar.png");	//Empty.png");
	gang.healthbar = LoadImage("hpbar.png");	//Empty_blue.png");
	gang.magbar = LoadImage("mpbar.png");
	//gang.limbar = LoadImage("Empty_lim.png");
	
	gang.indicator = LoadAnimation("greenarrow.mng");
	gang.indicateX = 0;
	gang.indicateY = 0;
	gang.indicateT = 0;
	gang.pointX = 5;
	gang.pointY = 170;
	gang.pointX2 = 0;
	gang.pointY2 = 0;
	gang.menuOffset = 0;
	gang.toppy = 0;
	gang.itemfin = 0;
	gang.healamount;
	gang.thelisto = [];
	
	gang.trixrows = [];
	gang.trixcols = [];
	gang.foeally = 0;
	
	gang.messwithdir = [];
	
	gang.init_time = GetTime();
	gang.last_inc_times = new Array(gang.init_time, gang.init_time, gang.init_time, gang.init_time);
	gang.lastframetime = gang.init_time;
	gang.timedif = 0;
	gang.popupdelay = 0;	//frames before menu switch (5)
	gang.linelengths = new Array(0,0,0,0);
	gang.ischarready = new Array(false, false, false, false);
	gang.gangbegins = new Array();
	gang.busy = new Array();
	gang.menuorder = new Array();
	gang.menuplacement = 0;
	gang.moveorder = new Array();
	gang.movecoms = new Array();
	gang.moveplacement = 0;
	gang.commandmark = 0;
	gang.guydirs = new Array();
	gang.theguys = new Array();		//east0, east1, east2, fight, down1, yeah, owch
	gang.setdirs = new Array();
	gang.flip = (gang.backattack || reverse) ? 0 : 1;		//guys should face left/right
	gang.dudeXs = new Array();
	gang.dudeYs = new Array();
	gang.menumode = "free";
	gang.evilmask = -1;
	gang.tarfin = 0;
	gang.gangXmods = new Array();
	gang.gangYmods = new Array();
	gang.yeahyerdone = false;
	gang.pause4event = false;
	gang.showbatbars = true;
	gang.framecount = 0;	//for timebar flashing
	
	/* INIT THE ENEMIES */
	for (var a=0; a<gang.list.length; a++)
	{
		if (gang.gangisent[a])
		{
			gang[a].x = GetPersonX(gang.gangisent[a]);
			gang[a].y = GetPersonY(gang.gangisent[a]);
			
		}
		if (!gang[a].tx) gang[a].tx = gang[a].x;
		if (!gang[a].ty) gang[a].ty = gang[a].y;
		gang.gangXmods[a] = 0;
		gang.gangYmods[a] = 0;
		gang.gangbegins[a] = GetTime();
		gang.busy[a] = false;
		gang[a].vigor = randomnum(58,65);
		gang[a]['hp_max'] = gang[a]['hp'];
		if (!RT)
		{
			if (gang[a].sprite)
			{
				gang[a].ss = eval(gang.img);
				gang[a].stances = new Array();
				for (var f13=0; f13<gang[a].ss.directions.length; f13++)
				{
					if (gang[a].ss.directions[f13].name == "west")
					{ gang[a].stances[0] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[0].index ];
					   gang[a].stances[1] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[1].index ];
					   gang[a].stances[2] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[2].index ]; }
					if (gang[a].ss.directions[f13].name == "fight")
					   gang[a].stances[3] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[0].index ];
					if (gang[a].ss.directions[f13].name == "down1")
					   gang[a].stances[4] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[0].index ];
					if (gang[a].ss.directions[f13].name == "yeah")
					   gang[a].stances[5] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[0].index ];
					if (gang[a].ss.directions[f13].name == "owch")
					   gang[a].stances[6] = gang[a].ss.images[ gang[a].ss.directions[f13].frames[0].index ];
				}
			}
			else  if (!gang.gangisent[a]) gang[a].img = eval(gang[a].img);	//load the enemy images!!
		}
		if (!gang.gangisent[a]) gang[a].img = eval(gang[a].img);	//can have enemies from LoadImage in BRT as well (terrurtle)
	}
	
	gang.thedudelimits = new Array(69, 0, 99, 10);	//replace with real stats - charstats[party[x]].limit or somethin
	gang.fonth = font.getHeight();
	gang.white = CreateColor(248,248,248,255);
	gang.green = CreateColor(0,255,0,255);
	gang.grey = CreateColor(128,128,128,255);
	gang.blue = CreateColor(0,0,128,255);
	gang.yellow = CreateColor(248,216,0,255);
	gang.pausecol = CreateColor(0,0,0,150);
	gang.redlim = CreateColor(255,0,0, 255);
	gang.whitemask = CreateColor(255,255,255,255);
	
	gang.time_outer = CreateColor(41, 41, 41, 255);
	gang.time_inner = CreateColor(69, 69, 69, 255);
	gang.time_middle = CreateColor(88, 96, 126, 255);
	gang.time_outerb = CreateColor(69, 69, 69, 255); 
     gang.time_innerb = CreateColor(88, 96, 126, 255); 
     gang.time_middleb = CreateColor(114, 114, 169, 255);
	gang.lim_top = CreateColor(163, 14, 14, 255);
	gang.lim_bot = CreateColor(221, 19, 19, 255);
	gang.hp_outer = CreateColor(33, 37, 75, 255);
	gang.hp_inner = CreateColor(48, 54, 107, 255);
	gang.hp_middle = CreateColor(73, 82, 163, 255);
	gang.mp_outer = CreateColor(43, 74, 34, 255);
	gang.mp_inner = CreateColor(58, 101, 46, 255);
	gang.mp_middle = CreateColor(81, 140, 64, 255);
	
	/*INITIATE THE PARTY!  WOO!*/
	gang.sprites = new Array();
	gang.menuopts = [];
	for (var i=0; i<party.length; i++)
	{
		gang.menuopts[party[i]] = ["Attack", 0, 0, "Item"];		//replace with customization later, everyone is same for now
		gang.messwithdir[i] = true;
		gang.theguys[i] = new Array();
		gang.guydirs[i] = 0;
		if (gang.dudeisent[i]) gang.dudeXs[i] = GetPersonX(gang.dudeisent[i]);
		else gang.dudeXs[i] = 80-i*10;
		gang.distbet = gang[0].x - gang.dudeXs[0];
		gang.midpoint = gang[0].x - gang.distbet/2;
		if (gang.flip==0 && !gang.dudeisent[i]) gang.dudeXs[i] = gang.midpoint + (gang.distbet/2 - 16);	//mirror image 
		if (gang.dudeisent[i]) gang.dudeYs[i] = GetPersonY(gang.dudeisent[i]);
		else gang.dudeYs[i] = 68+i*20+((4-party.length)*10);	//arrange them diagonally
		gang.sprites[i] = LoadSpriteset(charstats[party[i]].rss);
		for (var r10=0; r10<gang.sprites[i].directions.length; r10++)
		{
			if (gang.sprites[i].directions[r10].name == "west")
			{gang.theguys[i][0] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
			  gang.theguys[i][1] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[1].index ];
			  gang.theguys[i][2] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[2].index ]; }
			if (gang.sprites[i].directions[r10].name == "fight")
			   gang.theguys[i][3] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
			if (gang.sprites[i].directions[r10].name == "down1")
			  gang.theguys[i][4] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
			if (gang.sprites[i].directions[r10].name == "yeah")
			   gang.theguys[i][5] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
			if (gang.sprites[i].directions[r10].name == "owch")
			   gang.theguys[i][6] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
			if (gang.sprites[i].directions[r10].name == "crouch")
			   gang.theguys[i][7] = gang.sprites[i].images[ gang.sprites[i].directions[r10].frames[0].index ];
		}
	}
	if (!RT)
		gang.backdrop.blit(0,0);

	//constant gfx throughout battle..
	/* NAME AND STAT WINDOW */
	window.drawWindow(8, 164, 100, 67);
		alphagrad.transformBlit(5,161,  94,161,  94,234,  5,234);
	window.drawWindow(103, 164, 208, 67);
		alphagrad.transformBlit(100,161,  315,161,  315,234,  100,234);
	/* MAX HPs AND TIMEBARS */
	for (var q=0; q<party.length; q++)
	{
		gang.timebar.blit(108, 169+q*gang.fonth*1.55);
		//gang.limbar.blit(117, 173+q*gang.fonth*1.55);
		gang.healthbar.blit(180, 169+q*gang.fonth*1.55);
		gang.magbar.blit(252, 169+q*gang.fonth*1.55);
		//font.drawText(212, 165+q*gang.fonth*1.55, charstats[party[q]].hp_max);
	}
	
}	




function battleRT(agang, reverse, dudeisent, gangisent, showdamage)
{
	battleignition(agang, true, reverse, dudeisent, gangisent, showdamage);
	
	if (gang.flip==0)
		for (n=0; n<gang.list.length; n++)	//flip em over to other side
			;//if (!gang.gangisent[n]) gang[n].x = gang.midpoint - (gang.distbet/2  );// + gang[n].img.width);
	
	gang.backdrop = GrabImage(0,168-ybo,320,240);
	if (IsInputAttached()) gang.reattachinp = true;
	DetachInput();
	SetUpdateScript("BRTINPUT();");
	SetRenderScript("battal(); rendition();");
	getter('NEWsfx/PlayersTurn.mp3').play(false);
	posecheck();
}

function battal()
{
	with (gang)
	{
	if (((ganglives() && partylives()) || moveorder[moveplacement]!=undefined) &&  gang.fighting)	//dont stop til dude's done movin
	{
	
	
	if (showbatbars) 
	backdrop.blit(0,168-ybo);
	
	if (backattack && GetTime() < init_time + 2000)
	{
		var srtwd = font.getStringWidth("Back Attack!");
		window.drawWindow(GetScreenWidth()/2-strwd/2-15, ybo, strwd+30, 10);
		alphagrad.transformBlit
		(
			GetScreenWidth()/2 -strwd/2 -15, ybo-6, GetScreenWidth()/2+strwd/2+15, ybo-6,
			GetScreenWidth()/2+strwd/2+15, ybo+18, GetScreenWidth()/2 -strwd/2 -15, ybo+18
		);
		font.drawText(GetScreenWidth()/2-strwd/2, ybo, "Back Attack!");
	}

	//font.drawText(5,220, gang[0].x + ", " + gang[0].y);
	
	for (var b=0; b<list.length; b++)
	{
		if (gang[b].hp > 0)
		{
		//DRAW THEM
			if (gangisent[b])		//in this part we just continually set the *person's* coords, cause they are on the map engine
			{							//in order to move them, gangXYmods must be adjusted
				if (!pause4event)
				{
					SetPersonX(gangisent[b], gang[b].x + gangXmods[b]);
					SetPersonY(gangisent[b], gang[b].y + gangYmods[b]);
				}
			}
			else					//otherwise they are drawn to the screen because they are images, not *persons*
			{
				var x = map2screenX(gang[b].x),				y = map2screenY(gang[b].y);
				var w = gang[b].img.width,		h = gang[b].img.height;
				var xm = gangXmods[b],		ym = gangYmods[b];
				var temp = flip; if (gang[b].opface) flip = 0;
				gang[b].img.transformBlitMask
				(
					x+xm+w*flip,	y+ym, 
					x+xm+w-w*flip,	y+ym,
					x+xm+w-w*flip,	y+ym+h,
					x+xm+w*flip,	y+ym+h,
					(b==evilmask)?Black:White
				);
				flip = temp;
			}
			
		//TIME THEM
			if (gangbegins[b] + gang[b].speed*200 < GetTime() && !gang[b].timid && list[b]!=undefined && !pause4event)
			{
				if (!busy[b]){ busy[b] = true; moveorder.push("enemyAttack("+b+");"); }
			}
		}
	}
	
	if (menumode=="whom" && !pause4event)
	{		//point at alive enemy!
		if (gang[tarfin].hp <= 0 || list[tarfin]==undefined){ for (var z=0; z<list.length; z++) if (gang[z].hp > 0) {tarfin = z; break;}}
//		pointer.blit((gangisent[tarfin]) ? map2screenX(gang[tarfin].x + gangXmods[tarfin])-20 : gang[tarfin].x+gangXmods[tarfin]-15,   (gangisent[tarfin]) ? map2screenY(gang[tarfin].y+gangYmods[tarfin])-10 : gang[tarfin].y+gangYmods[tarfin] + 0.3*gang[tarfin].img.height);
		pointer.blit(map2screenX(gang[tarfin].tx + gangXmods[tarfin])-20,   map2screenY(gang[tarfin].ty+gangYmods[tarfin])-10);
		window.drawWindow(160-font.getStringWidth(gang[tarfin].name)/2-5, ybo, font.getStringWidth(gang[tarfin].name)+10, font.getHeight());
		font.drawText(160-font.getStringWidth(gang[tarfin].name)/2, ybo, gang[tarfin].name);
	}
	if (menumode=="item_whom" && !pause4event)
	{
		pointer.blit(map2screenX(dudeXs[tarfin])-20,   map2screenY(dudeYs[tarfin])-10);
		window.drawWindow(160-font.getStringWidth(party[tarfin])/2-5, ybo, font.getStringWidth(party[tarfin])+10, font.getHeight());
		font.drawText(160-font.getStringWidth(party[tarfin])/2, ybo, party[tarfin]);
	}
	if (showbatbars)
	{
		var tempfrcnt = framecount;	// used to allow only one framecount increment, multiple dudes make it RAPID
		for (var i=0;i<party.length;i++)
		{
			/* NAME, SPRITE, HP */
			if (menuorder[menuplacement]==undefined) font.drawText(4+xbo*2,165+i*fonth*1.55, charstats[party[i]].name);
			if (!pause4event) if (charstats[party[i]].hp <= 0 && theguys[i][4]) guydirs[i] = 4;	//charstats[party[i]].hp = 0;	//non negative
			var img = theguys[i][guydirs[i]];
			if (dudeisent[i] && !pause4event) {SetPersonX(dudeisent[i], dudeXs[i]); SetPersonY(dudeisent[i], dudeYs[i]);}
				
			else img.transformBlit(
				dudeXs[i]+img.width*flip,				dudeYs[i],
				dudeXs[i]+img.width-img.width*flip,	dudeYs[i],
				dudeXs[i]+img.width-img.width*flip,	dudeYs[i]+img.height,
				dudeXs[i]+img.width*flip,				dudeYs[i]+img.height
			);
			font.drawText(220-font.getStringWidth(charstats[party[i]].hp), 161+i*fonth*1.55, charstats[party[i]].hp);
	
			if (notdead(i))
			{
				/* TIMEBAR STUFF */
				Line(110, 170+i*fonth*1.55,110+linelengths[i], 170+i*fonth*1.55, flashbar(i, "outer"));
				Line(110, 171+i*fonth*1.55,110+linelengths[i], 171+i*fonth*1.55, flashbar(i, "inner"));
				Line(110, 172+i*fonth*1.55,110+linelengths[i], 172+i*fonth*1.55, flashbar(i, "middle"));
				Line(110, 173+i*fonth*1.55,110+linelengths[i], 173+i*fonth*1.55, flashbar(i, "inner"));
				Line(110, 174+i*fonth*1.55,110+linelengths[i], 174+i*fonth*1.55, flashbar(i, "outer"));
				
				if (!ischarready[i] && !paused && !pause4event)
				{
					if (linelengths[i] < 51)
						{ if (last_inc_times[i] + 7500/(charstats[party[i]].speed^2) <= GetTime()) {linelengths[i]++; last_inc_times[i] = GetTime();} }
					else	
					{ischarready[i] = true; menuorder.push(i); } //put the dude index in queue
				}
				if (ischarready[i] && tempfrcnt==framecount) {if (framecount >= 10)  framecount = 0; framecount++; }
			}
			
			/* LIMITBAR STUFF */
			Line(109, 176+i*fonth*1.55,111+32*(thedudelimits[i]/100), 176+i*fonth*1.55, lim_top);
			Line(109, 177+i*fonth*1.55,111+32*(thedudelimits[i]/100), 177+i*fonth*1.55, lim_bot);
			
			/* HEALTHBAR STUFF */
			Line(182, 170+i*fonth*1.55,182+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 170+i*fonth*1.55, hp_outer);
			Line(182, 171+i*fonth*1.55,182+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 171+i*fonth*1.55, hp_inner);
			Line(182, 172+i*fonth*1.55,182+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 172+i*fonth*1.55, hp_middle);
			Line(182, 173+i*fonth*1.55,182+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 173+i*fonth*1.55, hp_inner);
			Line(182, 174+i*fonth*1.55,182+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 174+i*fonth*1.55, hp_outer);
			
			/* MAGICBAR STUFF */
			Line(252, 170+i*fonth*1.55,252+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 170+i*fonth*1.55, mp_outer);
			Line(252, 171+i*fonth*1.55,252+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 171+i*fonth*1.55, mp_inner);
			Line(252, 172+i*fonth*1.55,252+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 172+i*fonth*1.55, mp_middle);
			Line(252, 173+i*fonth*1.55,252+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 173+i*fonth*1.55, mp_inner);
			Line(252, 174+i*fonth*1.55,252+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 174+i*fonth*1.55, mp_outer);
		}
	}
	if (!pause4event)
	{
		if (menuorder[menuplacement]!=undefined)
		{
			if (popupdelay==0)
			handlemenuRT(menuorder[menuplacement]);
			else popupdelay--;
		}
		
		if (moveorder[moveplacement]!=undefined)						//if move exists
		{
			if (commandmark==0)									//not moving?
				{ commandmark=1; eval(moveorder[moveplacement]);}			//prepare the move (call function)
			else 													//else execute the move (do steps)
			{
				eval(movecoms[commandmark-1]);
				if (commandmark < movecoms.length)
					commandmark++;
			}
		}
		if (gang.eventrig)	//usually halts battle
		 if (!battleventrigs[gang.eventrig].happened[ battleventrigs[eventrig].condmark ]) 
		  if (gang.eventrig.condtype)	//all or oneattatime
		   for (var h=0; h<gang.eventrig.condition.length; h++) eval(battleventrigs[gang.eventrig].condition[h]);
		  else eval(battleventrigs[gang.eventrig].condition[ battleventrigs[gang.eventrig].condmark ]);
	}
	else		// finally paused4event
	{		// battle event kernel... sorta
		if (bproceed)
		{
			if (beventmark >= bevq.length)
			{
				bevq = new Array();
				beventmark = 0;
				gang.pause4event = false;
			}
			else
			{
				eval(bevq[beventmark]);
				beventmark++;
			}
		}
		
		if (talkmode) thetalkingstuff();
	}
	// FPS LIMIT: 30ish	(not needed in map engine)
	
	if (paused){ApplyColorMask(pausecol); font.drawText(160-font.getStringWidth("SPEADU")/2, 120, "PAUSED");}
	
//	font.drawTextBox(5,0,350,230,10,tarfin);
//	font.drawTextBox(5,5,350,230,10,moveplacement+": "+moveorder[moveplacement]+"\n"+commandmark+"\n"+movecoms[commandmark-1]);

	//if (IsKeyPressed(KEY_ESCAPE)) paused = !paused;
	//if (IsKeyPressed(KEY_MINUS)) charstats[party[0]].hp -= Math.round(charstats[party[0]].hp_max*.015);
	//if (IsKeyPressed(KEY_EQUALS)) charstats[party[0]].hp += Math.round(charstats[party[0]].hp_max*.015);
	}
	else	//gang is dead and dude's done movin
	{
		if (!ganglives())
		{
		//do dance-arounds and rewards
		gang.fighting=false;
		SetUpdateScript("updation();");
		SetRenderScript("rendition();");
		if (gang.reattachinp) AttachInput(thePC.name);
		if (!dontproceed) proceed = true;
		dontproceed = false;
		if (gang.eventrig && battleventrigs[gang.eventrig].afterbat) eval(battleventrigs[gang.eventrig].afterbat);
		}
		else if (!partylives())
		{
			Abort("------DEATH-------DEATH-------DEATH-------\n\n		Thanks for playing, wuss!\n\n-------DEATH-------DEATH-------MEGADETH-------");
		}
	}
	}	//with
}

function flashbar(i, omg)
{
	var nf = false;	//no flash
	if (gang.eventrig=="fitz_battle") nf = true;
	with (gang)
	{
		if (omg=="outer")
		{
			if (ischarready[i] && framecount >= 5 && !nf) return time_outerb;
			else return time_outer;
		}
		if (omg=="inner")
		{
			if (ischarready[i] && framecount >= 5 && !nf) return time_innerb;
			else return time_inner;
		}
		if (omg=="middle")
		{
			if (ischarready[i] && framecount >= 5 && !nf) return time_middleb;
			else return time_middle;
		}
	}
}

function  handlemenuRT(fighter)
{
	if (!notdead(fighter))
	{
		gang.menuplacement++;
		gang.popupdelay=5;
		gang.pointY = 170;
		gang.menumode = "free";
		return;
	}
			
	window2.drawWindow(15, 173, 72, 40);
	if (gang.menuopts[party[fighter]][0]) font.drawText(23, 170, gang.menuopts[party[fighter]][0]);
	if (gang.menuopts[party[fighter]][1]) font.drawText(23, 182, gang.menuopts[party[fighter]][1]);
	if (gang.menuopts[party[fighter]][2]) font.drawText(23, 194, gang.menuopts[party[fighter]][2]);
	if (gang.menuopts[party[fighter]][3]) font.drawText(23, 206, gang.menuopts[party[fighter]][3]);

	if (gang.menumode=="free" || gang.menumode=="whom")
		pointer.blit(gang.pointX, gang.pointY);
	
	if (gang.menumode=="item_sel" || gang.menumode=="item_whom")
	{
		window.drawWindow(10, 167, 298, 63);	
		alphagrad.transformBlit(10-xbo, 167-ybo,   10+298+xbo*2, 167-ybo,   10+298+xbo*2, 167+63+ybo*2,   10-xbo, 167+63+ybo*2);
	
		gang.thelisto = new Array();		//only display possessed items
		for (var r=0; r<itemlist.length; r++) 
			if (items[itemlist[r]].quantity>0)	gang.thelisto[items[itemlist[r]].order] = itemlist[r];
	
		Rectangle(306,165, 5, 68, CreateColor(255,255,255, 60));
		for (var d=0; d<13; d++)
		{
			if (items[gang.thelisto[d+gang.toppy]])													{	//whoa!!
			font2.drawText(25, 168+d*12, items[gang.thelisto[d+gang.toppy]].name);
			font2.drawText(220, 168+d*12, ": " + items[gang.thelisto[d+gang.toppy]].quantity);		}
		}
		Rectangle(306,165+(gang.toppy/287)*60,5,5, Cyan);
		pointer.blit(5, 168+gang.itemfin*12);

	}
	
/*	font.drawText(23, 170, "Attack");
	font.drawText(23, 182, "Magic");
	font.drawText(23, 206, "Item");

	if (party[fighter]=="Kefka")
	{	//custom menu junk
		font.drawText(23, 194, party[fighter]);
	}
*/
	gang.indicator.drawFrame( ((gang.dudeisent[fighter]) ? map2screenX(gang.dudeXs[fighter])-7 : gang.dudeXs[fighter]+5) , ((gang.dudeisent[fighter]) ? map2screenY(gang.dudeYs[fighter])-17 : gang.dudeYs[fighter])-10 );
	if (gang.indicator.getDelay() + gang.indicateT < GetTime()){gang.indicator.readNextFrame(); gang.indicateT = GetTime();}
	if (gang.theguys[fighter][3]) gang.guydirs[fighter] = 3;
}


function BRTINPUT()
{
	if (gang.pause4event) return;
	if (AreKeysLeft() && gang.menuorder[gang.menuplacement]!=undefined)	//someone's menu is up
	{
	switch (GetKey())
	{
		case key_talk:
		{
			if (gang.pointY==170 && gang.menumode=="free")
			{
				gang.menumode = "whom";
			}
			else if (gang.pointY==170 && gang.menumode=="whom")
			{				
				gang.moveorder.push("basicAttack("+gang.menuorder[gang.menuplacement]+","+ gang.tarfin+");");
				gang.menuplacement++;
				gang.menu_up = false;
				gang.popupdelay=5;
				gang.menumode="free";
			}
			else if (gang.pointY==206 && gang.menumode=="free")
			{
				gang.menumode = "item_sel";
			}
			else if (gang.menumode=="item_sel")
			{
				gang.menumode="item_whom";
				tarfin = gang.menuorder[gang.menuplacement];
			}
			else if (gang.menumode=="item_whom")
			{
				gang.moveorder.push("itemAttack("+gang.menuorder[gang.menuplacement]+ ",'" + gang.tarfin + "','" + gang.thelisto[gang.itemfin+gang.toppy] + "');");
				gang.menuplacement++;
				gang.menu_up = false;
				gang.popupdelay=5;
				gang.menumode="free";

			}
			break;
		}
		case KEY_UP:
		{
			if (gang.menumode=="free")
			{
				var yPoint = gang.pointY;
				for (var g=(gang.pointY-170)/12; g>0; g--)
					if (gang.menuopts[party[ gang.menuorder[gang.menuplacement] ]][g-1]){ gang.pointY = 170+(g-1)*12; break; }
				if (yPoint == gang.pointY)
				for (var g=3; g>(gang.pointY-170)/12; g--)
					if (gang.menuopts[party[ gang.menuorder[gang.menuplacement] ]][g]){ gang.pointY += g*12; break; }
			}
			else if (gang.menumode=="whom")
			{
				var fintar = gang.tarfin;
				//go back checking, if hasn't changed:start from end
				if (gang.tarfin > 0)
				for (var t=gang.tarfin-1; t>=0; t--) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=gang.list.length-1; b>gang.tarfin; b--) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			else if (gang.menumode=="item_sel")
			{
				if (gang.itemfin+gang.toppy > 0)
					if (gang.itemfin==0)
						gang.toppy--;
					else gang.itemfin--;		
			}
			else if (gang.menumode=="item_whom")
			{
				if (gang.tarfin>0) gang.tarfin--;
			}
			break;
		}
		case KEY_DOWN:
		{
			if (gang.menumode=="free")
			{
				var yPoint = gang.pointY;
				for (var g=(gang.pointY-170)/12 + 1; g<=3; g++)
					if (gang.menuopts[party[ gang.menuorder[gang.menuplacement] ]][g]){ gang.pointY = 170+g*12; break; }
				if (yPoint == gang.pointY)
				for (var g=0; g<(gang.pointY-170)/12; g++)
					if (gang.menuopts[party[ gang.menuorder[gang.menuplacement] ]][g]){ gang.pointY = 170+g*12; break; }
			}
			else if (gang.menumode=="whom")
			{
				var fintar =gang.tarfin;
				//go up checking, if hasn't changed:start from begin
				for (var t=gang.tarfin+1; t<=gang.list.length-1; t++) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=0; b<gang.tarfin; b++) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			else if (gang.menumode=="item_sel")
			{
				if (gang.itemfin+gang.toppy < 299)
					if (gang.itemfin==4)
						gang.toppy++;
					else gang.itemfin++;
			}
			else if (gang.menumode=="item_whom")
			{
				if (gang.tarfin<party.length-1) gang.tarfin++;
			}
			break;
		}
		case key_cancel:
		{
			if (gang.menumode=="free")
			{
				gang.menuorder.push(gang.menuorder[gang.menuplacement]);
				gang.guydirs[gang.menuorder[gang.menuplacement]] = 0;
				gang.menuplacement++;
				gang.popupdelay=5;
				gang.pointY = 170;
			}
			else if (gang.menumode == "whom" || gang.menumode=="item_sel")
			{
				gang.menumode = "free";
			}
			else if (gang.menumode=="item_whom")
			{
				gang.menumode="item_sel";
			}
			break;		
		}
		case KEY_LEFT:
		{
			if (gang.menumode=="whom")
			{
				var fintar = gang.tarfin;
				//go back checking, if hasn't changed:start from end
				if (gang.tarfin > 0)
				for (var t=gang.tarfin-1; t>=0; t--) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=gang.list.length-1; b>gang.tarfin; b--) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			break;
		}
		case KEY_RIGHT:
		{
			if (gang.menumode=="whom")
			{
				var fintar =gang.tarfin;
				//go up checking, if hasn't changed:start from begin
				for (var t=gang.tarfin+1; t<=gang.list.length-1; t++) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=0; b<gang.tarfin; b++) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			break;
		}
	}
	}
}


/*
// =========================\\
 --- --- --- REGULAR BATLE --- --- --- 
\\ =========================//
*/
	
function battle(agang)	//crazy parameters: monster gang/group, background, items, gp, exp?, fun, bossity
{
	battleignition(agang);
	
	if (gang.backattack)
		for (n=0; n<gang.list.length; n++)	//flip em over to other side
			gang[n].x = GetScreenWidth()/2 - (gang[n].x - GetScreenWidth()/2 + gang[n].img.width);
			
	gang.backdrop = GrabImage(0,0,320,240);
	
	gang.duderockon = true;
	
	with (gang)
	{
	while (duderockon)	//entire ATB loop
	{
		backdrop.blit(0,0);
			
		if (ganglives() && partylives())
		{

		if (GetTime() < init_time + 2000 && gang.backattack)
		{
			var thaWid = font.getStringWidth("Back Attack!");
			window.drawWindow(GetScreenWidth()/2-thaWid/2-15, ybo, thaWid+30, 10);
			alphagrad.transformBlit
			(
				GetScreenWidth()/2- thaWid/2-15-rfXo,		ybo-rfYo,
				GetScreenWidth()/2+thaWid/2+15+rfXo,		ybo-rfYo,
				GetScreenWidth()/2+thaWid/2+15+rfXo,		ybo+10+rfYo,
				GetScreenWidth()/2- thaWid/2-15-rfXo,		ybo+10+rfYo
			);	
			font.drawText(GetScreenWidth()/2-thaWid/2, ybo, "Back Attack!");
		}

		for (var b=0; b<gang.list.length; b++)
		{
			if (gang[b].hp > 0)
			{
			//DRAW THEM
				var x = gang[b].x,			y = gang[b].y;
				var w = gang[b].img.width, 	h = gang[b].img.height;
				var xm = gangXmods[b],		ym = gangYmods[b];
				var temp = flip; if (gang[b].opface) flip = 0;
				gang[b].img.transformBlitMask
				(
					x+xm+w*flip,	y+ym, 		x+xm+w-w*flip,	y+ym,
					x+xm+w-w*flip,	y+ym+h,		x+xm+w*flip,	y+ym+h,
					(b==evilmask) ? Black : White
				);
				flip = temp;
				
			//TIME THEM
				if (gangbegins[b] + gang[b].speed*200 < GetTime())
				{
					if (!busy[b]){ busy[b] = true; moveorder.push("enemyAttack("+b+");"); }
									//REPLACE WITH *THEIR* STANDARD MOVE
				}
			}
		}

		if (paused){ApplyColorMask(pausecol); font.drawText(160-font.getStringWidth("SPEADU")/2, 120, "PAUSED");}
		//font.drawTextBox(5,5,350,230,10,moveplacement+": "+moveorder[moveplacement]+"\n"+commandmark+"\n"+movecoms[commandmark-1]);
		if (IsKeyPressed(KEY_ESCAPE)) paused = !paused;
	
		if (IsKeyPressed(KEY_MINUS)) charstats[party[0]].hp -= Math.round(charstats[party[0]].hp_max*.015);
		if (IsKeyPressed(KEY_EQUALS)) charstats[party[0]].hp += Math.round(charstats[party[0]].hp_max*.015);

		}
		else		//-----!!!!!------!!!!----!!!!--THE GANG IS DEAD!!----!!!!----!!!------!!!!----!!!
		{
			if (!ganglives())
			{
			if (!gang.yeahyerdone)
				{gang.moveorder.push("dancearounds();"); gang.yeahyerdone = true;}	//only do once
			/*
			SetUpdateScript("updation();");
			SetRenderScript("rendition();");
			proceed = true;
			*/
			}
			else	//GAME OVER!
			{
				FlipScreen();
				font.drawZoomedText(35,35, 2, "NOT EVIL ENOUGH");
				FlipScreen();
				GetKey();
				ExitMapEngine();
				return;
			}
		}

		// ---------------DONE REGARDLESS OF GANGLIVES() ---------------
		
		for (var i=0;i<party.length;i++)
		{
			/* NAME, SPRITE, HP */
			if (menuorder[menuplacement]==undefined) font.drawText(15,165+i*fonth*1.55, charstats[party[i]].name);
			if (charstats[party[i]].hp <= 0 && theguys[i][4] && !gang.yeahyerdone) guydirs[i] = 4;
			var img = theguys[i][guydirs[i]];
			if (img)
			img.transformBlit(dudeXs[i]+img.width*flip, dudeYs[i],  dudeXs[i]+img.width-img.width*flip, dudeYs[i],  dudeXs[i]+img.width-img.width*flip, dudeYs[i]+img.height,  dudeXs[i]+img.width*flip, dudeYs[i]+img.height);
			font.drawText(212-font.getStringWidth(charstats[party[i]].hp + "/"), 165+i*fonth*1.55, charstats[party[i]].hp + "/");

			/* TIMEBAR STUFF */
/*			Point(112,167+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(111,168+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(112,168+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(112,169+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			
			Point(163,167+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(164,168+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(163,168+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			Point(163,169+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			
			Line(114, 167+i*fonth*1.55,161, 167+i*fonth*1.55, (ischarready[i]) ? blue : grey); 
			Line(114, 169+i*fonth*1.55,161, 169+i*fonth*1.55, (ischarready[i]) ? blue : grey);
			*/
			if (charstats[party[i]].hp > 0)	//the dead have no actions (dunno bout zombie stat)
			{			
			
		// old one		Line(114, 168+i*fonth*1.55,114+linelengths[i], 168+i*fonth*1.55, (ischarready[i]) ? yellow : green);
			Line(110, 170+i*fonth*1.55,110+linelengths[i], 170+i*fonth*1.55, (ischarready[i]) ? time_outer : time_outer);
			Line(110, 171+i*fonth*1.55,110+linelengths[i], 171+i*fonth*1.55, (ischarready[i]) ? time_inner : time_inner);
			Line(110, 172+i*fonth*1.55,110+linelengths[i], 172+i*fonth*1.55, (ischarready[i]) ? time_middle : time_middle);
			Line(110, 173+i*fonth*1.55,110+linelengths[i], 173+i*fonth*1.55, (ischarready[i]) ? time_inner : time_inner);
			Line(110, 174+i*fonth*1.55,110+linelengths[i], 174+i*fonth*1.55, (ischarready[i]) ? time_outer : time_outer);
			
		
			// TIMEBAR ALGORITHM (needs non-frame-dependent revision)
			if (!ischarready[i] && !paused && ganglives())
			{
				if (last_inc_times[i] + 7500/(charstats[party[i]].speed^2) <= GetTime())
					{linelengths[i]++; last_inc_times[i] = GetTime();}
				if (linelengths[i] >= 47){ ischarready[i] = true; menuorder.push(i); } //put the dude index in queue
			}
			}
			/* LIMITBAR STUFF */
			Line(109, 176+i*fonth*1.55,111+32*(thedudelimits[i]/100), 176+i*fonth*1.55, lim_top);
			Line(109, 177+i*fonth*1.55,111+32*(thedudelimits[i]/100), 177+i*fonth*1.55, lim_bot);
	
			
			/* HEALTHBAR STUFF */
			Line(184, 176+i*fonth*1.55,184+(charstats[party[i]].hp/charstats[party[i]].hp_max)*47, 176+i*fonth*1.55, white);
		}
		

		if (menumode=="whom")
		{		//point at alive enemy!
			if (gang[tarfin].hp <= 0){ for (var z=0; z<=gang.list.length-1; z++) if (gang[z].hp > 0) {tarfin = z; break;}}
			pointer.blit(gang[tarfin].x-15, gang[tarfin].y + 0.3*gang[tarfin].img.height);
			window.drawWindow(160-font.getStringWidth(gang[tarfin].name)/2-5, ybo, font.getStringWidth(gang[tarfin].name)+10, font.getHeight());
			font.drawText(160-font.getStringWidth(gang[tarfin].name)/2, ybo, gang[tarfin].name);
		}
		if (menuorder[menuplacement]!=undefined)
		{
			if (popupdelay==0)
			handlemenu(menuorder[menuplacement]);
			else { popupdelay--; while (AreKeysLeft()) GetKey(); }
		}			
		else while (AreKeysLeft()) GetKey();

	
		
		if (moveorder[moveplacement]!=undefined)						//if move exists
		{
			if (commandmark==0)									//not moving?
				{ commandmark=1; eval(moveorder[moveplacement]);}			//prepare the move
			else 													//else execute the move
			{ eval(movecoms[commandmark-1]);	if (commandmark < movecoms.length) commandmark++;}
		}
		
		
		// FPS LIMIT: 30ish
		timedif = GetTime() - lastframetime;
		if (timedif < 40)	while (GetTime() < lastframetime + (40 - timedif));
		lastframetime = GetTime();
		
		FlipScreen();
		

	}	//not rockingout
	}	//with

}

function begintimes()
{
	for (var b=0; b<gang.list.length; b++)
		gang.gangbegins[b] = GetTime();
}

function notdead(foo)
{
	if (charstats[party[foo]].hp <= 0) return false;
	else return true;
}

function inflict(foo, harmach)
{
}

function healergood(mofoo, harrrmaaach)
{
}

function handlemenu(fighter)
{
	if (gang.pause4event) return;
	if (charstats[party[fighter]].hp < 1)
	{
		gang.menuplacement++;
		gang.popupdelay=5;
	}

  // this will get moved somewhere else
	var i = 0;
	var spells = new Array();
	spells[i++] = "|Fire  "; spells[i++] = "|Ice   "; spells[i++] = "|Bolt  ";
	spells[i++] = "|      "; spells[i++] = "|      "; spells[i++] = "|      ";
	spells[i++] = "|Fire2 "; spells[i++] = "|Ice2  "; spells[i++] = "|Bolt2 ";
	spells[i++] = "|      "; spells[i++] = "|      "; spells[i++] = "|      ";
	spells[i++] = "|Fire3 "; spells[i++] = "|Ice3  "; spells[i++] = "|Bolt3 ";
	spells[i++] = "|      "; spells[i++] = "|      "; spells[i++] = "|      ";
	spells[i++] = "|      "; spells[i++] = "|      "; spells[i++] = "|Ultima";

	spells[i++] = "{Cure  "; spells[i++] = "{      "; spells[i++] = "{      ";
	spells[i++] = "{      "; spells[i++] = "{      "; spells[i++] = "{      ";
	spells[i++] = "{Cure2 "; spells[i++] = "{      "; spells[i++] = "{      ";
	spells[i++] = "{      "; spells[i++] = "{      "; spells[i++] = "{      ";
	spells[i++] = "{Cure3 "; spells[i++] = "{      "; spells[i++] = "{      ";
	spells[i++] = "{      "; spells[i++] = "{      "; spells[i++] = "{      ";
	
	spells[i++] = "}Scan  "; spells[i++] = "}      "; spells[i++] = "}      ";
	spells[i++] = "}      "; spells[i++] = "}      "; spells[i++] = "}      ";
	spells[i++] = "}      "; spells[i++] = "}      "; spells[i++] = "}      ";
	spells[i++] = "}      "; spells[i++] = "}      "; spells[i++] = "}      ";
	spells[i++] = "}      "; spells[i++] = "}      "; spells[i++] = "}      ";
	spells[i++] = "}      "; spells[i++] = "}X-Fer "; spells[i++] = "}      ";
	
	gang.indicator.drawFrame(gang.dudeXs[fighter]+7, gang.dudeYs[fighter]-7);
	if (gang.indicator.getDelay() + gang.indicateT < GetTime()){gang.indicator.readNextFrame(); gang.indicateT = GetTime();}
	if (gang.theguys[fighter][3]) gang.guydirs[fighter] = 3;
	window2.drawWindow(15, 173, 72, 40);
	if( gang.menumode == "magic" ) {
		window.drawWindow(18, 172, 172, 42);
			
	  for( i = gang.menuOffset * 3; i < (gang.menuOffset * 3)+12; i++ ) {
			if( charspells[party[fighter]][i] >= 100 )
				font.drawText(26+(i%3)*54, 170+Math.floor( (i-(i%3))/3 - gang.menuOffset ) * 12, spells[i]);
	  }
		pointer.blit(gang.pointX2,gang.pointY2);
	}
	else {
		font.drawText(23, 170, "Attack");
		font.drawText(23, 182, "Magic");
		font.drawText(23, 206, "Item");
		pointer.blit(gang.pointX,gang.pointY);
	
		switch (party[fighter])
		{	// custom menu junk
			case "Kefka":
				font.drawText(23, 194, "Test"); break;
			default:
				font.drawText(23, 194, party[fighter]); break;
		}
  }
	if (AreKeysLeft())
	{
	switch (GetKey())
	{
		case key_talk:
		{
			// Attack
			if (gang.pointY==170 && gang.menumode=="free")
			{
				gang.menumode = "whom";
			}
			else if (gang.pointY==170 && gang.menumode=="whom")
			{				
				gang.moveorder.push("basicAttack("+fighter+","+ gang.tarfin+");");
				gang.menuplacement++;
				gang.menu_up = false;
				gang.popupdelay=5;
				gang.menumode="free";
			}
			// Magic
			if( gang.pointY == 182 && gang.menumode == "free") {
				gang.menumode="magic";
				gang.pointX2 = 8;
				gang.pointY2 = 170;
				gang.menuOffset = 0;

				// Lolz
			}
			// Character Specific Ability
			if( gang.pointY == 194 && gang.menumode == "free" ) {
				// Crap goes here
			}
			// Item
			if( gang.pointY == 206 && gang.menumode == "free" ) {
				// junk
			}
			break;
		}
		case KEY_UP:
		{
			if ( gang.menumode=="free" && gang.pointY > 170 ) gang.pointY-=12;	//when other options are
			if (gang.menumode=="whom")
			{
				var fintar = gang.tarfin;
				//go back checking, if hasn't changed:start from end
				if (gang.tarfin > 0)
				for (var t=gang.tarfin-1; t>=0; t--) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=gang.list.length-1; b>gang.tarfin; b--) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			else if( gang.menumode=="magic" ) {
				gang.pointY2 -= 12;
				if( gang.pointY2 < 170 ) {
					gang.pointY2 = 170;
					gang.menuOffset--;
					if( gang.menuOffset == -1 ) gang.menuOffset = 0;
				}
			}
			break;
		}
		case KEY_DOWN:
		{
			if( gang.menumode == "free" && gang.pointY < 206 ) gang.pointY+=12;
			if (gang.menumode=="whom")
			{
				var fintar = gang.tarfin;
				//go up checking, if hasn't changed:start from begin
				for (var t=gang.tarfin+1; t<=gang.list.length-1; t++) if (gang[t].hp > 0) {gang.tarfin = t; break;}
				if (fintar == gang.tarfin)
				for (var b=0; b<gang.tarfin; b++) if (gang[b].hp > 0) {gang.tarfin = b; break;}
			}
			else if( gang.menumode == "magic" ) {
				gang.pointY2 += 12;
				if( gang.pointY2 > 206 ) {
					gang.pointY2 = 206;
					gang.menuOffset++;
					if( gang.menuOffset > 15 ) gang.menuOffset = 15;
				}
			}
			break;
		}
		case KEY_LEFT:
		{
			if( gang.menumode == "magic" ) {
				gang.pointX2 -= 54;
				if( gang.pointX2 < 8 ) {
					gang.pointX2 = 116;
					gang.pointY2 -= 12;
					if( gang.pointY2 < 170 ) {
						gang.pointX2 = 116;
						gang.pointY2 = 170;
						gang.menuOffset--;
						if( gang.menuOffset == -1 ) {
							gang.pointX2 = 8;
							gang.menuOffset = 0;
						}
					}
				}
			}
			break;
		}
		case KEY_RIGHT:
		{
			if( gang.menumode == "magic" ) {
				gang.pointX2 += 54;
				if( gang.pointX2 > 116 ) {
					gang.pointX2 = 8;
					gang.pointY2 += 12;
					if( gang.pointY2 > 206 ) {
						gang.pointX2 = 8;
						gang.pointY2 = 206;
						gang.menuOffset++;
						if( gang.menuOffset > 15 ) {
							gang.pointX2 = 116;
							gang.menuOffset = 15;
						}
					}
				}
			}
			break;
		}
		case key_cancel:
		{
			if (gang.menumode=="free")
			{
				gang.menuplacement++;
				gang.menuorder.push(fighter);
				gang.guydirs[fighter] = 0;
				gang.popupdelay=5;
			}
			else if (gang.menumode == "whom" || gang.menumode == "magic" )
			{
				gang.menumode = "free";
			}
			break;
		}
	}	
	}
	
}

function basicAttack(mr, targ)
{
		//no zombies!
	if (charstats[party[mr]].hp <= 0) return;
		//attack *alive*, *existing* enemy!
	if (gang[targ].hp <= 0 || gang.list[targ]==undefined)
	{
		for (var z=0; z<gang.list.length; z++)
		{
			if (gang[z].hp > 0) {targ = z; break;}
			if (z==gang.list.length-1) {gang.commandmark=0; gang.moveplacement++; return;}	//all DEAD!
		}
	}
	
	if (charstats[party[mr]].vigor>=128) var vigor2 = 255; else var vigor2 = charstats[party[mr]].vigor*2;
	var damage = charstats[party[mr]].batpow + ((charstats[party[mr]].level * charstats[party[mr]].level * (charstats[party[mr]].batpow + vigor2)) / 256) *1.5;
	damage = (damage * randomnum(224,255) / 256) + 1;
	damage = Math.floor((damage * (255 - gang[targ].att_def) / 256) + 1);
	if (damage < 0) damage = 0;
	
	var dwid = ( ((gang.gangisent[targ]) ? 24 : gang[targ].img.width) ) /2 - font.getStringWidth(damage)/2;
	var dhei = ( ((gang.gangisent[targ]) ? 24 : gang[targ].img.height) )*0.4;
	var ydude = gang.dudeYs[mr];
	var thaX = (gang.gangisent[targ]) ? map2screenX(gang[targ].x-7) : map2screenX(gang[targ].x);	//i didn't think both needed conversion.. hm!
	var thaY = (gang.gangisent[targ]) ? map2screenY(gang[targ].y-15) : map2screenY(gang[targ].y);
	
	moveq("if (theguys[" + mr + "][5]) guydirs[" + mr + "] = 5;");	//yeah
	moveq("dudeXs["+mr+"]-=6+6*flip*-2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]-=6+6*flip*-2; dudeYs["+mr+"] = " + (ydude-7));
	moveq("dudeXs["+mr+"]-=5+5*flip*-2; dudeYs["+mr+"] = " + (ydude-8));
	moveq("dudeXs["+mr+"]-=5+5*flip*-2; dudeYs["+mr+"] = " + (ydude-6));
	moveq("dudeXs["+mr+"]-=4+4*flip*-2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]-=3+3*flip*-2; dudeYs["+mr+"] = " + (ydude-2));
	moveq("dudeXs["+mr+"]-=2+2*flip*-2; dudeYs["+mr+"] = " + (ydude));
	moveq(";");
	moveq("if (theguys[" + mr + "][3]) guydirs[" + mr + "] = 3;");
	moveq("gangXmods[" + targ + "] = -3+3*flip*2; getter('Strike.ogg').play(false);");				//impact!
	moveq(";");
	moveq(";");
	moveq(";");
	moveq(";");
	moveq(";");
	moveq("gangXmods[" + targ + "] = 0;");
	if (!gang.showdamage)
	{
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei)    +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-3) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-5) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-4) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-3) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-2) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei-1) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei)    +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+2) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+2) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+3) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+4) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+6) +", "+damage+");");
	moveq("font.drawText(" + (thaX+dwid) + "," + (thaY+dhei+8) +", "+damage+");");
	}
	else for (var b=0; b<14; b++) moveq(";");
	moveq("if (theguys[" + mr + "][5]) guydirs[" + mr + "] = 5;");
	moveq("dudeXs["+mr+"]+=6-6*flip*2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]+=6-6*flip*2; dudeYs["+mr+"] = " + (ydude-10));
	moveq("dudeXs["+mr+"]+=5-5*flip*2; dudeYs["+mr+"] = " + (ydude-12));
	moveq("dudeXs["+mr+"]+=5-5*flip*2; dudeYs["+mr+"] = " + (ydude-15));
	moveq("dudeXs["+mr+"]+=4-4*flip*2; dudeYs["+mr+"] = " + (ydude-12));
	moveq("dudeXs["+mr+"]+=3-3*flip*2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]+=2-2*flip*2; dudeYs["+mr+"] = " + (ydude));
	moveq("gang["+targ+"].hp -= "+damage); 					//monster takes a (huge) hit
	if (gang[targ].counters) moveq("moveorder.splice(moveplacement+1, 0, gang["+targ+"].counters[Math.floor(Math.random()*gang["+targ+"].counters.length)]);");
	moveq("guydirs["+mr+"]= 0; ischarready[" + mr + "] = false; linelengths[" + mr + "] = 0; commandmark=0; moveplacement++; clearmoveq();");
}

function moveq(hugestuff)
{
	gang.movecoms[gang.movecoms.length] = hugestuff;
}

function clearmoveq()
{
	gang.movecoms = new Array();
}

function ganglives()
{
	if (!gang.fighting) return false;
	for (var p=0; p<gang.list.length; p++)
	if (gang[p].hp > 0) return true;
	return false;
}

function partylives()
{
	var retval = false;
	for (var m=0; m<party.length; m++)
		if (charstats[party[m]].hp <= 0) charstats[party[m]].hp = 0;		//prevents negative hp
		else retval = true;
	return retval;
}

function posecheck()
{
	for (var b=0; b<party.length; b++)
	{
		if (gang.messwithdir[b])
		{
			if (!notdead(b)) if (gang.theguys[b][4]) SetPersonDirection(party[b], "down1");
			else if (charstats[party[b]].hp < charstats[party[b]].hp_max*.15)
				if (gang.theguys[b][7]) SetPersonDirection(party[b], "crouch");
			else 
				if (gang.theguys[b][3]) SetPersonDirection(party[b], "fight");
		}
	}
}

function getfightdir(sir)
{	//add support for other chars, other dir names, etc
	if (gang.reverse) return "fight";
	else return "fight2";
}
function randomnum(min,max)
{
	do var mcgraw = Math.round(Math.random()*max);
	while (mcgraw < min || mcgraw > max)
	return mcgraw;
}

function verynextmove(jank)	//THIS SUCKS DONT FUCKING USE IT!! ARRAY SPLICING RULES
{
	var augment = new Array();
	for (var b=0; b<gang.moveorder.length; b++)
	{
		if (b == gang.moveplacement)
			augment[augment.length+1] = jank;
		else augment[augment.length] = gang.moveorder[b];
	}
	gang.moveorder = augment;	
}

function enemyAttack(beast)
{
	if (gang[beast].hp < 1 || !partylives() || gang.list[beast]==undefined)	//no zombies!
	{
		gang.commandmark=0;
		gang.moveplacement++;
		return true;
	}
	do var guy = Math.floor(Math.random()*party.length);
	while (charstats[party[guy]].hp <= 0)
	
	var infliction = gang[beast].lvl * gang[beast].lvl * (gang[beast].strength*4+gang[beast].vigor) / 256;
	infliction = (infliction * randomnum(224,255) / 256) + 1;
	infliction = Math.floor((infliction * (255 - charstats[party[guy]].defense) / 256) + 1);
	
	var thaX = (gang.dudeisent[guy]) ? map2screenX(gang.dudeXs[guy]-7) : gang.dudeXs[guy];
	var thaY = (gang.dudeisent[guy]) ? map2screenY(gang.dudeYs[guy]-15) : gang.dudeYs[guy];
	var yguy = gang[beast].y;

// split between img (blinks) and sprite (jumps)
	if (gang.gangisent[beast])
	{
		// jump frwd	
		//maybe test some jump poses	//moveq("if (theguys[" + mr + "][5]) guydirs[" + mr + "] = 5;");	//yeah
		
		moveq("gangXmods["+beast+"]+=6+6*flip*-2; gangYmods["+beast+"] = -5;");
		moveq("gangXmods["+beast+"]+=6+6*flip*-2; gangYmods["+beast+"] = -7;");
		moveq("gangXmods["+beast+"]+=5+5*flip*-2; gangYmods["+beast+"] = -8;");
		moveq("gangXmods["+beast+"]+=5+5*flip*-2; gangYmods["+beast+"] = -6;");
		moveq("gangXmods["+beast+"]+=4+4*flip*-2; gangYmods["+beast+"] = -5;");
		moveq("gangXmods["+beast+"]+=3+3*flip*-2; gangYmods["+beast+"] = -2;");
		moveq("gangXmods["+beast+"]+=2+2*flip*-2; gangYmods["+beast+"] = 0;");
	}
	else
	{
		moveq("evilmask = "+beast+";");
														moveq(";"); moveq(";");
		moveq("evilmask = -1;");
		moveq("evilmask = "+beast+";");
														moveq(";"); moveq(";");
		moveq("evilmask = -1;");
														moveq(";"); moveq(";"); moveq(";");
	}
//	moveq("if (theguys["+guy+"][6] && notdead("+guy+")) if (dudeisent["+guy+"]) SetPersonDirection(party["+guy+"],  'owch'); else guydirs["+guy+"] = 6;");
	moveq("dudeXs["+guy+"]+=5-5*flip*2;");
	moveq("getter('smack.ogg').play(false);");
	moveq(";"); moveq(";"); moveq(";"); moveq(";");
//	moveq("if (theguys["+guy+"][1] && notdead("+guy+")) if (dudeisent["+guy+"]) SetPersonDirection(party["+guy+"], getfightdir("+guy+")); else guydirs["+guy+"] = 1;");
//	moveq("if (notdead("+guy+")) guydirs["+guy+"] = 0;");
	moveq("dudeXs["+guy+"]-=5-5*flip*2;");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+10)    + "," +infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-2+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-3+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-5+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-4+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-3+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-2+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY-1+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+10)    + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+2+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+3+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+4+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+6+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+8+10) + ", "+infliction+");");
	moveq("font.drawText("+(thaX+4) +","+ (thaY+8+10) + ", "+infliction+");");
	moveq("posecheck();");
	
	if (gang.gangisent[beast])	//jump back in place
	{
	//	moveq("if (theguys[" + mr + "][5]) guydirs[" + mr + "] = 5;");
		moveq("gangXmods["+beast+"]-=6-6*flip*2; gangYmods["+beast+"] = -5;");
		moveq("gangXmods["+beast+"]-=6-6*flip*2; gangYmods["+beast+"] = -10;");
		moveq("gangXmods["+beast+"]-=5-5*flip*2; gangYmods["+beast+"] = -12;");
		moveq("gangXmods["+beast+"]-=5-5*flip*2; gangYmods["+beast+"] = -15;");
		moveq("gangXmods["+beast+"]-=4-4*flip*2; gangYmods["+beast+"] = -12;");
		moveq("gangXmods["+beast+"]-=3-3*flip*2; gangYmods["+beast+"] = -5;");
		moveq("gangXmods["+beast+"]-=2-2*flip*2; gangYmods["+beast+"] = 0;");
	}
	moveq("charstats[party["+guy+"]].hp -= "+infliction+";");
	moveq("gangbegins["+beast+"]=GetTime(); busy["+beast+"] = false; commandmark=0; moveplacement++; clearmoveq();");
}


function dancearounds()
{
	//gang.moveorder = [];
	//gang.moveplacement = 0;
	//gang.movecoms = [];
	var stringer = "";
	var stringer2 = "";
	for (var f=0; f<4; f++)
	{
		for (var g=0; g<party.length; g++)
			stringer += "guydirs[" + g + "] = 5;";
		moveq(stringer);
		for (var h=0; h<10; h++)
		moveq(";");
		for (var g=0; g<party.length; g++)
			stringer2 += "guydirs[" + g + "] = 0;";
		moveq(stringer2);
		for (var h=0; h<10; h++)
		moveq(";");
	}
	moveq("gang.duderockon = false;");
}

function batevnobj()
{
	var graw = new Object();
	graw.condition = [];
	graw.happened = [];
	graw.condtype = 0;		//0: sequential conditions; 1: check all in array
	graw.condmark = 0;	//sequence placement marker
	return graw;
}


var battleventrigs = [];
battleventrigs['rockoutdude'] = batevnobj();
battleventrigs['rockoutdude'].condition[0] = "if (gang[0].hp < gang[0].hp_max*.8) {battleventrigs['rockoutdude'].condmark++; guitarrockation(); }";
battleventrigs['rockoutdude'].condition[1] = "if (gang[0].hp < gang[0].hp_max*.3) {battleventrigs['rockoutdude'].condmark++; anotherjammer(1);}";
battleventrigs['rockoutdude'].afterbat = "DestroyPerson('rudess'); DestroyPerson('portno'); DestroyPerson('banger'); fukkinmetalbgm.stop();";

battleventrigs['guardtrio'] = batevnobj();
battleventrigs['guardtrio'].condition[0] = "if (gang[0].hp <=0 || gang[1].hp <=0 || gang[2].hp <= 0) guardtrioflee();";

battleventrigs['firstshard'] = batevnobj();
battleventrigs['firstshard'].condition[0] = "SetDelayScript(90, 'zapchauncy();'); battleventrigs['firstshard'].condmark++; gang[0].timid=true;";
battleventrigs['firstshard'].condition[1] = "if (gang[0].hp < gang[0].hp_max){ SetPersonDirection('taddle', 'welldone'); SetPersonFrame('taddle', 1); gang.fighting=false; }";

battleventrigs['fitz_battle'] = batevnobj();
battleventrigs['fitz_battle'].condition[0] = "SetDelayScript(70, 'destroyfitz();'); battleventrigs['fitz_battle'].condmark++;";

battleventrigs['terrurtle'] = batevnobj();
battleventrigs['terrurtle'].condition[0] = "holdit_thinkback(); battleventrigs['terrurtle'].condmark++;";
battleventrigs['terrurtle'].condition[1] = "if (gang[1].hp < gang[1].hp_max*.8) { battleventrigs['terrurtle'].condmark++; hideinshell(); }";
battleventrigs['terrurtle'].condition[2] = "if (gang[1].hp < gang[1].hp_max*.6) { battleventrigs['terrurtle'].condmark++; hideinshell(); }";
battleventrigs['terrurtle'].condition[3] = "if (gang[1].hp < gang[1].hp_max*.4) { battleventrigs['terrurtle'].condmark++; hideinshell(); }";
battleventrigs['terrurtle'].condition[4] = "if (gang[1].hp < gang[1].hp_max*.2) { battleventrigs['terrurtle'].condmark++; hideinshell(); }";
battleventrigs['terrurtle'].condition[5] = "if (gang[1].hp <= 0) { gang[0].hp=0; gang[1].hp=0; }";


//battleventrigs['finalboss']		=	batevnobj("if (yergay) cannotwin_gameover();");





function earthquake(vil)
{
	gang.busy[vil] = true;
	
	var thaX = [], thaY=[];
	var damage = "'??'";	//replace with whatev
	
	for (var dangit=0; dangit<party.length; dangit++)
	{
		thaX[dangit] = (gang.dudeisent[dangit]) ? map2screenX(gang.dudeXs[dangit]-7) : gang.dudeXs[dangit];
		thaY[dangit] = (gang.dudeisent[dangit]) ? map2screenY(gang.dudeYs[dangit]-15) : gang.dudeYs[dangit];
	}

	moveq("dispTown = 'Earthquake';");
	for (var geez=0; geez<50; geez++)		//geez!!
	moveq(";");
	moveq("dispTown=false;");
	
	moveq("getter('quake.ogg').play(false);");
	
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	for (var golly=0; golly<party.length; golly++)	//golly!!
	moveq("if (notdead("+golly+") && gang.messwithdir["+golly+"]) SetPersonDirection(party["+golly+"], 'owch');");	//owch	//WONT WORK IN NON-RT BATTLES LUFL
	
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	for (var golly=0; golly<party.length; golly++)	//golly!!
	moveq("if (notdead("+golly+") && gang.messwithdir["+golly+"]) SetPersonDirection(party["+golly+"], 'down1');");	//owch
	
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+15);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()-10);");
	moveq(";");moveq(";");
	moveq("SetCameraY(GetCameraY()+5);");
	
	for (var geez=0; geez<10; geez++)		//geez!!
	moveq(";");
	
	var coorjunks = [-3, -5, -4, -3, -2, -1, 0, 2, 2, 3, 4, 6, 8, 8, 8, 8, 8, 8, 8];
	
	for (var harrg=0; harrg<coorjunks.length; harrg++)
	{
		var stringathon = "";
		for (var woo0o=0; woo0o<party.length; woo0o++)
			if (notdead(woo0o)) stringathon += "font.drawText(" + (thaX[woo0o]) + "," + (thaY[woo0o]+coorjunks[harrg]) + ", " + damage + ");";
		moveq(stringathon);
	}

	for (var geez=0; geez<10; geez++)		//geez!!
	moveq(";");
	
//	for (var ugh=0; ugh<party.length; ugh++)
//	moveq("charstats[party["+ugh+"]].hp -= " + damage + ";");
	
	moveq("posecheck();");
	for (var golly=0; golly<party.length; golly++)	//golly!!
	moveq("if (notdead("+golly+")) SetPersonDirection(party["+golly+"], 'fight');");	//whew
	
	for (var yikes=0; yikes<20; yikes++)		//yikes!!
	moveq(";");
	
	
	moveq("gangbegins["+vil+"]=GetTime(); busy["+vil+"] = false; commandmark=0; moveplacement++; clearmoveq();");
}




function itemAttack(mr, targ, item_id)
{
		//no zombies!
	if (charstats[party[mr]].hp <= 0) return;
	
	var ydude = gang.dudeYs[mr];
	var thaX = (gang.dudeisent[targ]) ? map2screenX(gang.dudeXs[targ]-7) : gang.dudeXs[targ];	//repair these when the time comes
	var thaY = (gang.dudeisent[targ]) ? map2screenY(gang.dudeYs[targ]-15) : gang.dudeYs[targ];

//	insert a check whether the font should go over the person using item or someone else (he jumps forward but font stays)

	gang.healamount = "";
	
	moveq("if (theguys[" + mr + "][5]) guydirs[" + mr + "] = 5;");	//yeah
	moveq("dudeXs["+mr+"]-=6+6*flip*-2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]-=6+6*flip*-2; dudeYs["+mr+"] = " + (ydude-7));
	moveq("dudeXs["+mr+"]-=5+5*flip*-2; dudeYs["+mr+"] = " + (ydude-8));
	moveq("dudeXs["+mr+"]-=5+5*flip*-2; dudeYs["+mr+"] = " + (ydude-6));
	moveq("dudeXs["+mr+"]-=4+4*flip*-2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]-=3+3*flip*-2; dudeYs["+mr+"] = " + (ydude-2));
	moveq("dudeXs["+mr+"]-=2+2*flip*-2; dudeYs["+mr+"] = " + (ydude));
	moveq(";");
	moveq("if (theguys[" + mr + "][3]) guydirs[" + mr + "] = 3;");
	moveq(";");
	moveq(";");
	moveq(";");
	moveq(";");
	moveq(";");
	moveq("getter('newSFX/item-use.mp3').play(false);");
	moveq("gang.healamount = USE_ITEM('"+item_id + "', '" + party[targ] + "');");
	moveq("font2.setColorMask(CreateColor(190, 190, 255, 255));");
	moveq("font2.drawText(" + (thaX) + "," + (thaY)    +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-3) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-5) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-4) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-3) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-2) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY-1) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY)    +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+2) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+2) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+3) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+4) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+6) +", gang.healamount);");
	moveq("font2.drawText(" + (thaX) + "," + (thaY+8) +", gang.healamount);");
	moveq("font2.setColorMask(White);");
	moveq("posecheck();");

	moveq("dudeXs["+mr+"]+=6-6*flip*2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]+=6-6*flip*2; dudeYs["+mr+"] = " + (ydude-10));
	moveq("dudeXs["+mr+"]+=5-5*flip*2; dudeYs["+mr+"] = " + (ydude-12));
	moveq("dudeXs["+mr+"]+=5-5*flip*2; dudeYs["+mr+"] = " + (ydude-15));
	moveq("dudeXs["+mr+"]+=4-4*flip*2; dudeYs["+mr+"] = " + (ydude-12));
	moveq("dudeXs["+mr+"]+=3-3*flip*2; dudeYs["+mr+"] = " + (ydude-5));
	moveq("dudeXs["+mr+"]+=2-2*flip*2; dudeYs["+mr+"] = " + (ydude));
	moveq("guydirs["+mr+"]= 0; ischarready[" + mr + "] = false; linelengths[" + mr + "] = 0; commandmark=0; moveplacement++; clearmoveq();");
}
